These outputs will provide information on local areas, 2013 area units, and statistical area 2 units, and 2018 Meshblocks.
Four csv files:
# load libraries
import geopandas as gpd # vector data
import pandas as pd # tabular data, loading CSVs
import numpy as np # numeric data
from util import *
import matplotlib.pyplot as plt # plotting
from tqdm.auto import tqdm # progress bars
import json
from shapely.geometry import Point, shape # creating points
import requests # web requests
from pprint import pprint
plt.rcParams['figure.figsize'] = (20, 20)
ls()
| name | filesize (MB) | last modified | |
|---|---|---|---|
| 0 | 2013-mb-dataset-Total-New-Zealand-Household.csv | 37.12 | 2021-07-20 09:51:53.970000 |
| 1 | CSTDAT8700_Output_20210607.zip | 217.69 | 2021-06-30 09:37:35.480000 |
| 2 | MASTER_UP_BaseZone_SHP.zip | 66.92 | 2021-07-20 09:51:54.490000 |
| 3 | Modified_Community_Boards_SHP.zip | 1.30 | 2021-06-30 11:55:11.883103 |
| 4 | lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip | 4.25 | 2021-08-06 11:54:33.440000 |
| 5 | statsnzmeshblock-higher-geographies-2018-generalised-FGDB.zip | 34.54 | 2021-08-06 11:54:34.670000 |
| 6 | statsnzpopulation-by-meshblock-2013-census-FGDB.zip | 82.11 | 2021-07-20 09:51:54.950000 |
Total: 444.0MB
df = gpd.read_file("input/Modified_Community_Boards_SHP.zip")
df.OBJECTID = df.OBJECTID.astype(int)
df = df.set_index("OBJECTID", drop=True)
df = df.sort_index()
df
| Local_Area | geometry | |
|---|---|---|
| OBJECTID | ||
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... |
| 2 | Beach Haven-Birkenhead-Northcote | POLYGON ((1757287.966 5925962.738, 1757211.333... |
| 3 | Botany | POLYGON ((1770748.846 5912611.168, 1770889.893... |
| 4 | Devonport-Takapuna | POLYGON ((1755276.581 5932026.336, 1755278.305... |
| 5 | East Coast Bays | POLYGON ((1756125.006 5940268.048, 1756139.852... |
| 6 | Franklin-Beachlands-Hunua | MULTIPOLYGON (((1804302.354 5890738.079, 17905... |
| 7 | Franklin-Pukekohe | POLYGON ((1765085.620 5897344.807, 1765096.229... |
| 8 | Franklin-Waiuku | POLYGON ((1744829.308 5899882.633, 1744835.760... |
| 9 | Henderson-Massey | POLYGON ((1745963.138 5923457.510, 1745945.884... |
| 10 | Hibiscus Coast | MULTIPOLYGON (((1752023.352 5954803.281, 17520... |
| 11 | Howick | POLYGON ((1771447.460 5916900.636, 1771474.703... |
| 12 | Mangere-Otahuhu | MULTIPOLYGON (((1766142.746 5910838.845, 17661... |
| 13 | Manurewa | POLYGON ((1769432.488 5904664.673, 1769471.312... |
| 14 | Maungakiekie | POLYGON ((1759418.674 5915517.660, 1759596.351... |
| 15 | Mt Albert | POLYGON ((1756291.061 5918265.104, 1756266.530... |
| 16 | Mt Eden | POLYGON ((1751910.995 5920299.659, 1751917.632... |
| 17 | Orakei | POLYGON ((1759833.395 5920429.502, 1759837.143... |
| 18 | Otara | MULTIPOLYGON (((1765765.640 5909501.655, 17657... |
| 19 | Pakuranga | POLYGON ((1769523.742 5920466.582, 1769527.337... |
| 20 | Papakura | POLYGON ((1772188.699 5902202.011, 1772192.566... |
| 21 | Papatoetoe | POLYGON ((1765105.421 5908611.893, 1765113.661... |
| 22 | Puketapapa | POLYGON ((1753132.892 5915040.177, 1753141.101... |
| 23 | Rodney-Dairy Flat | POLYGON ((1746055.938 5948651.765, 1746067.112... |
| 24 | Rodney-Helensville | MULTIPOLYGON (((1710567.626 5967865.416, 17106... |
| 25 | Rodney-Kumeu-Riverhead | POLYGON ((1742532.808 5931237.574, 1742490.377... |
| 26 | Rodney-Warkworth | MULTIPOLYGON (((1761692.564 5984690.018, 17617... |
| 27 | Rodney-Wellsford | MULTIPOLYGON (((1746318.204 6000215.757, 17464... |
| 28 | Tamaki | POLYGON ((1765594.677 5917986.938, 1765609.808... |
| 29 | Titirangi | POLYGON ((1749038.038 5910572.842, 1749034.230... |
| 30 | Upper Harbour Local Board Area | MULTIPOLYGON (((1743880.554 5928979.708, 17438... |
| 31 | Waiheke | MULTIPOLYGON (((1793981.864 5931917.843, 17940... |
| 32 | Waitakere | MULTIPOLYGON (((1743890.310 5905057.188, 17438... |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... |
df = df.rename(columns={"Local_Area": "Name"})
df["Centroid_lon"] = df.centroid.x
df["Centroid_lat"] = df.centroid.y
df["Area"] = df.area
%%time
zones = gpd.read_file("input/MASTER_UP_BaseZone_SHP.zip")
zones
CPU times: user 16.1 s, sys: 482 ms, total: 16.5 s Wall time: 16.5 s
| OBJECTID | CONTOUR | created_da | DocumentUR | GlobalID | GROUPZONE | GROUPZONE_ | last_edite | NAME | PARCEL_BAS | ... | TYPE | TYPE_resol | VERSIONSTA | VERSIONS_1 | ZONE | ZONE_resol | ZONEHEIGHT | SHAPE_Leng | SHAPE_Area | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | None | 20160718211 | None | {4C8F9436-7EA6-417E-B64F-15FCD44459F6} | 2 | Residential | 20161111010 | None | None | ... | None | None | 4 | Operative | 60 | Residential - Mixed Housing Urban Zone | NaN | 285.664016 | 2.050275e+03 | POLYGON ((1768030.306 5901206.846, 1768033.070... |
| 1 | 2.0 | None | 20160718211 | None | {604AAD87-8ED4-4111-8276-47CEE7E81F92} | 1 | Public Open Space | 20161111010 | None | None | ... | None | None | 4 | Operative | 33 | Open Space - Sport and Active Recreation Zone | NaN | 1246.837757 | 1.684599e+04 | POLYGON ((1764267.286 5919989.370, 1764218.153... |
| 2 | 3.0 | None | 20160718211 | None | {8D827DA8-BC5B-437A-B17A-532354F7D037} | 4 | Rural | 20161111010 | None | None | ... | None | None | 4 | Operative | 11 | Rural - Mixed Rural Zone | NaN | 3582.113246 | 6.841744e+05 | POLYGON ((1740091.195 5928308.839, 1740089.844... |
| 3 | 4.0 | None | 20160718211 | None | {96C9E266-3341-4C71-94F1-325F2EE45732} | 2 | Residential | 20161111010 | None | None | ... | None | None | 4 | Operative | 23 | Residential - Large Lot Zone | NaN | 317.098469 | 6.024226e+03 | POLYGON ((1750502.125 5928677.635, 1750456.131... |
| 4 | 5.0 | None | 20160718211 | None | {90B50FEE-45A3-4E88-819A-370751ACDE3D} | 1 | Public Open Space | 20161111010 | None | None | ... | None | None | 4 | Operative | 31 | Open Space - Conservation Zone | NaN | 230.836636 | 5.639794e+02 | POLYGON ((1741460.217 5918191.600, 1741476.745... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 130295 | 130296.0 | None | 20161115151 | None | {B2F0FB45-80F6-41ED-AA57-A914B195B31E} | 1 | Public Open Space | 20161115151 | None | None | ... | None | None | 4 | Operative | 31 | Open Space - Conservation Zone | NaN | 179382.307787 | 9.040193e+07 | POLYGON ((1738072.631 5902593.421, 1738095.386... |
| 130296 | 130297.0 | None | 20161115151 | None | {A3F4EF61-9162-43C3-90BD-DC84D93C6A64} | 2 | Residential | 20161115151 | None | None | ... | None | None | 4 | Operative | 18 | Residential - Mixed Housing Suburban Zone | NaN | 2769.292040 | 2.920602e+05 | POLYGON ((1770189.642 5905789.775, 1770199.407... |
| 130297 | 130298.0 | None | 20161115151 | None | {A5FC7EB5-76E5-414C-96DD-715C671764B4} | 4 | Rural | 20161115151 | Kaipara South Head and Harbour coastal area | None | ... | None | None | 4 | Operative | 46 | Rural - Rural Coastal Zone | NaN | 27168.762393 | 6.344938e+06 | POLYGON ((1730253.401 5955767.484, 1730254.399... |
| 130298 | 130299.0 | None | 20161115151 | None | {C371B83C-35CE-46A1-B94F-F1E592F271F7} | 2 | Residential | 20161115151 | None | None | ... | None | None | 4 | Operative | 8 | Residential - Terrace Housing and Apartment Bu... | NaN | 1812.109533 | 1.536829e+05 | POLYGON ((1743032.759 5924130.564, 1742996.886... |
| 130299 | 130300.0 | None | 20161115151 | None | {31281924-C74D-4038-8260-FE6D886F4C94} | 2 | Residential | 20161115151 | None | None | ... | None | None | 4 | Operative | 18 | Residential - Mixed Housing Suburban Zone | NaN | 2511.267945 | 3.539606e+05 | POLYGON ((1748979.767 5925771.895, 1748986.615... |
130300 rows × 31 columns
zones[pd.isna(zones.ZONE_resol)]
| OBJECTID | CONTOUR | created_da | DocumentUR | GlobalID | GROUPZONE | GROUPZONE_ | last_edite | NAME | PARCEL_BAS | ... | TYPE | TYPE_resol | VERSIONSTA | VERSIONS_1 | ZONE | ZONE_resol | ZONEHEIGHT | SHAPE_Leng | SHAPE_Area | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 20853 | 20854.0 | None | 20160718211 | None | {2D83F680-9587-4D57-AF0B-CB7CA27C3D2C} | 6 | Special purpose zone | 20161111011 | None | None | ... | None | None | 4 | Operative | 58 | None | NaN | 72.629617 | 22.286945 | POLYGON ((1767684.860 5903714.023, 1767691.955... |
| 121765 | 121766.0 | None | 20160718211 | None | {FD3E8BB4-1979-42B5-9A77-5D04AE5190AF} | 6 | Special purpose zone | 20161111010 | None | None | ... | None | None | 4 | Operative | 58 | None | NaN | 86.135341 | 4.114962 | POLYGON ((1767684.083 5903713.690, 1767666.954... |
2 rows × 31 columns
zones.ZONE_resol = zones.ZONE_resol.fillna("Special")
zones.GROUPZONE_.value_counts()
General 52461 Coastal 42200 Residential 22398 Public Open Space 6667 Business 3237 Rural 2750 Special purpose zone 299 New growth 288 Name: GROUPZONE_, dtype: int64
zones.ZONE_resol.value_counts()
Road 47012 Coastal - General Coastal Marine Zone 26326 Coastal - Coastal Transition Zone 15703 Residential - Mixed Housing Suburban Zone 9775 Residential - Mixed Housing Urban Zone 5864 Strategic Transport Corridor Zone 4215 Residential - Single House Zone 3766 Open Space - Conservation Zone 3063 Open Space - Informal Recreation Zone 2926 Residential - Terrace Housing and Apartment Building Zone 2134 Rural - Rural Production Zone 1025 Water 1013 Business - Mixed Use Zone 782 Rural - Rural Coastal Zone 768 Business - Light Industry Zone 593 Business - Neighbourhood Centre Zone 564 Residential - Rural and Coastal Settlement Zone 480 Open Space - Sport and Active Recreation Zone 477 Business - Town Centre Zone 432 Residential - Large Lot Zone 379 Rural - Mixed Rural Zone 344 Rural - Countryside Living Zone 326 Future Urban Zone 282 Business - Local Centre Zone 266 Hauraki Gulf Islands 221 Business - City Centre Zone 191 Open Space - Community Zone 183 Rural - Waitakere Ranges Zone 172 Business - Metropolitan Centre Zone 160 Business - Heavy Industry Zone 130 Special Purpose - School Zone 126 Coastal - Mooring Zone 124 Business - General Business Zone 103 Rural - Rural Conservation Zone 71 Rural - Waitakere Foothills Zone 44 Special Purpose - Cemetery Zone 41 Special Purpose - Quarry Zone 34 Special Purpose - Maori Purpose Zone 32 Special Purpose - Major Recreation Facility Zone 28 Special Purpose - Healthcare Facility and Hospital Zone 23 Coastal - Ferry Terminal Zone 20 Coastal - Marina Zone 20 Open Space - Civic Spaces Zone 18 Business - Business Park Zone 16 Special Purpose - Airports and Airfields Zone 9 Green Infrastructure Corridor 6 Special Purpose - Tertiary Education Zone 4 Coastal - Minor Port Zone 4 Coastal - Defence Zone 3 Special 2 Name: ZONE_resol, dtype: int64
# Create a dictionary mapping the first n character of the zone description to the desired variable name
zones_of_interest = {
"Residential": "Residential_area",
"Residential - Single House Zone": "SH_area",
"Residential - Mixed Housing Suburban Zone": "MHS_area",
"Residential - Mixed Housing Urban Zone": "MHU_area",
"Residential - Terrace Housing and Apartment Building Zone": "THA_area",
"Residential - Large Lot Zone": "LL_area",
"Future Urban Zone": "FU_area",
"Hauraki Gulf Islands": "HGI_area",
"Business": "Business_area",
"Rural": "Rural_area",
"Open Space": "Open_area"
}
%%time
for k,v in tqdm(zones_of_interest.items()):
subset = zones[zones.ZONE_resol.str.startswith(k)] # Just the matched zones (residential, business, rural etc)
print(k, len(subset))
clipped = gpd.clip(df, subset) # Clip the local areas to the matched zones
df[v] = clipped.area # Store the resulting area. Unit is m²
Residential 22398 Residential - Single House Zone 3766 Residential - Mixed Housing Suburban Zone 9775 Residential - Mixed Housing Urban Zone 5864 Residential - Terrace Housing and Apartment Building Zone 2134 Residential - Large Lot Zone 379 Future Urban Zone 282 Hauraki Gulf Islands 221 Business 3237 Rural 2750 Open Space 6667 CPU times: user 6min 5s, sys: 415 ms, total: 6min 6s Wall time: 6min 5s
skytower = Point(1757109.809, 5920500.841) # in NZGD2000 projection
df["Hdist_skytower"] = df.centroid.distance(skytower) # Unit is meters
df.plot(column="Hdist_skytower", legend=True)
<matplotlib.axes._subplots.AxesSubplot at 0x7fded247ce80>
coastline = df.dissolve().boundary.iloc[0]
df["Coast_indicator"] = df.intersects(coastline)
df[["Name", "Coast_indicator"]]
| Name | Coast_indicator | |
|---|---|---|
| OBJECTID | ||
| 1 | Auckland Central | True |
| 2 | Beach Haven-Birkenhead-Northcote | True |
| 3 | Botany | True |
| 4 | Devonport-Takapuna | True |
| 5 | East Coast Bays | True |
| 6 | Franklin-Beachlands-Hunua | True |
| 7 | Franklin-Pukekohe | True |
| 8 | Franklin-Waiuku | True |
| 9 | Henderson-Massey | True |
| 10 | Hibiscus Coast | True |
| 11 | Howick | True |
| 12 | Mangere-Otahuhu | True |
| 13 | Manurewa | True |
| 14 | Maungakiekie | True |
| 15 | Mt Albert | False |
| 16 | Mt Eden | True |
| 17 | Orakei | True |
| 18 | Otara | True |
| 19 | Pakuranga | True |
| 20 | Papakura | True |
| 21 | Papatoetoe | True |
| 22 | Puketapapa | True |
| 23 | Rodney-Dairy Flat | True |
| 24 | Rodney-Helensville | True |
| 25 | Rodney-Kumeu-Riverhead | True |
| 26 | Rodney-Warkworth | True |
| 27 | Rodney-Wellsford | True |
| 28 | Tamaki | True |
| 29 | Titirangi | True |
| 30 | Upper Harbour Local Board Area | True |
| 31 | Waiheke | True |
| 32 | Waitakere | True |
| 33 | Whau | True |
households = pd.read_csv("input/2013-mb-dataset-Total-New-Zealand-Household.csv")
households
/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py:3165: DtypeWarning: Columns (1,2) have mixed types.Specify dtype option on import or set low_memory=False. has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
| Area_Code_and_Description | Code | Description | 2001_Census_total_households_in_occupied_private_dwellings | 2006_Census_total_households_in_occupied_private_dwellings | 2013_Census_total_households_in_occupied_private_dwellings | 2001_Census_household_composition_for_households_in_occupied_private_dwellings_One-family_household_(with_or_without_other_people) | 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Two-family_household_(with_or_without_other_people) | 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Three_or_more_family_household_(with_or_without_other_people) | 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Other_multi-person_household | ... | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | MB 0000100 | 100 | NaN | 3.0 | 3.0 | 3.0 | ..C | ..C | ..C | ..C | ... | ..C | 3.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 3.0 |
| 1 | MB 0000200 | 200 | NaN | 27.0 | 27.0 | 30.0 | 15 | 3 | 0 | 0 | ... | 3 | 24.0 | 3 | 9 | 24 | 6 | 15 | 30 | 3 | 30.0 |
| 2 | MB 0000300 | 300 | NaN | 21.0 | 24.0 | 21.0 | 18 | 3 | 0 | 0 | ... | 0 | 24.0 | 0 | 6 | 12 | 3 | 9 | 18 | 3 | 18.0 |
| 3 | MB 0000400 | 400 | NaN | 9.0 | 9.0 | 9.0 | 6 | ..C | ..C | ..C | ... | ..C | 12.0 | ..C | ..C | 9 | ..C | 6 | 9 | ..C | 9.0 |
| 4 | MB 0000501 | 501 | NaN | 0.0 | 0.0 | 0.0 | ..C | ..C | ..C | ..C | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 49038 | Footnotes for specific variables or categories | 23 | Median total household income is rounded to th... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 49039 | Symbols | ..C | Confidential | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 49040 | Symbols | .. | not available | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 49041 | Symbols | * | not able to be calculated | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 49042 | Source | Statistics New Zealand | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
49043 rows × 258 columns
key = "2013_Census_total_household_income_(grouped)(2)(3)(4)_for_households_in_occupied_private_dwellings_Median_household_income_($)(18)(23)"
households_with_income = households[households.Area_Code_and_Description.str.startswith("MB") & (households[key] != "..C") & (households[key] != "*")].copy()
print(len(households_with_income))
households_with_income[key] = households_with_income[key].astype(int)
households_with_income[key].plot(kind="hist", bins=20, figsize=(10,10))
40300
<matplotlib.axes._subplots.AxesSubplot at 0x7fa51f7c7940>
meshblocks = gpd.read_file("input/statsnzpopulation-by-meshblock-2013-census-FGDB.zip!population-by-meshblock-2013-census.gdb")
meshblocks
| Meshblock | MeshblockNumber | Population_Count_Usual_Resident_2013 | Population_Count_Census_Night_2013 | geometry | |
|---|---|---|---|---|---|
| 0 | MB 0352700 | 0352700 | 0 | 0 | MULTIPOLYGON (((1753237.550 5923918.395, 17532... |
| 1 | MB 0728500 | 0728500 | 9 | 6 | MULTIPOLYGON (((1761011.438 5905840.848, 17610... |
| 2 | MB 0829300 | 0829300 | 93 | 99 | MULTIPOLYGON (((1739739.656 5899165.556, 17397... |
| 3 | MB 1280801 | 1280801 | 0 | 0 | MULTIPOLYGON (((1869852.595 5695096.558, 18714... |
| 4 | MB 2360001 | 2360001 | 0 | 0 | MULTIPOLYGON (((1623601.773 5423210.098, 16235... |
| ... | ... | ... | ... | ... | ... |
| 46616 | MB 0074002 | 0074002 | 0 | 0 | MULTIPOLYGON (((1741178.600 6046572.236, 17414... |
| 46617 | MB 3208002 | 3208002 | 78 | 81 | MULTIPOLYGON (((1770892.430 5911519.906, 17708... |
| 46618 | MB 3208003 | 3208003 | 36 | 36 | MULTIPOLYGON (((1771025.156 5911674.629, 17709... |
| 46619 | MB 3209001 | 3209001 | 84 | 87 | MULTIPOLYGON (((1771731.425 5912665.799, 17717... |
| 46620 | MB 3209002 | 3209002 | 75 | 81 | MULTIPOLYGON (((1771758.103 5912422.760, 17717... |
46621 rows × 5 columns
meshblocks.geometry = meshblocks.representative_point()
meshblocks = meshblocks.merge(households, left_on="Meshblock", right_on="Area_Code_and_Description")
meshblocks = gpd.sjoin(df, meshblocks, op="intersects")
meshblocks
| Name | geometry | Centroid_lon | Centroid_lat | Area | Residential_area | SH_area | MHS_area | MHU_area | THA_area | ... | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OBJECTID | |||||||||||||||||||||
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 9.0 | ..C | ..C | 6 | ..C | ..C | 6 | ..C | 9.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 3 | 21.0 | 0 | 15 | 18 | 0 | 18 | 18 | 3 | 21.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 6 | 30.0 | 3 | 24 | 15 | 0 | 12 | 30 | 3 | 33.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 9.0 | ..C | 6 | 9 | ..C | 9 | 12 | ..C | 12.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 9 | 33.0 | 6 | 15 | 12 | 0 | 9 | 24 | 9 | 33.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 3 | 54.0 | 0 | 42 | 45 | 6 | 42 | 51 | 6 | 54.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | ..C | 9.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | ..C | 3.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 3.0 |
11527 rows × 281 columns
group = meshblocks.groupby("OBJECTID")
df["Census2013_population"] = group["Population_Count_Usual_Resident_2013"].sum()
df["Census2013_dwellings"] = group["2013_Census_total_households_in_occupied_private_dwellings"].sum()
meshblocks_with_income = meshblocks[(meshblocks[key] != "..C") & (meshblocks[key] != "*")].copy()
meshblocks_with_income[key] = meshblocks_with_income[key].astype(int)
meshblocks_with_income
| Name | geometry | Centroid_lon | Centroid_lat | Area | Residential_area | SH_area | MHS_area | MHU_area | THA_area | ... | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OBJECTID | |||||||||||||||||||||
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 9.0 | ..C | ..C | 6 | ..C | ..C | 6 | ..C | 9.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 3 | 21.0 | 0 | 15 | 18 | 0 | 18 | 18 | 3 | 21.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 6 | 30.0 | 3 | 24 | 15 | 0 | 12 | 30 | 3 | 33.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 9.0 | ..C | 6 | 9 | ..C | 9 | 12 | ..C | 12.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 9 | 33.0 | 6 | 15 | 12 | 0 | 9 | 24 | 9 | 33.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 0 | 54.0 | 3 | 39 | 45 | 6 | 42 | 51 | 3 | 54.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 6 | 66.0 | 3 | 48 | 51 | 6 | 45 | 66 | 6 | 69.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 6 | 57.0 | 0 | 48 | 48 | 9 | 42 | 54 | 3 | 54.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 3 | 54.0 | 0 | 48 | 42 | 3 | 45 | 54 | 6 | 60.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 3 | 54.0 | 0 | 42 | 45 | 6 | 42 | 51 | 6 | 54.0 |
10830 rows × 281 columns
meshblocks_with_income["income*dwellings"] = meshblocks_with_income[key] * meshblocks_with_income["2013_Census_total_households_in_occupied_private_dwellings"]
meshblocks_with_income["income*dwellings"]
OBJECTID
1 405000.0
1 2274300.0
1 331200.0
1 1500000.0
1 624000.0
...
33 2565000.0
33 3622500.0
33 4860000.0
33 3900000.0
33 3331800.0
Name: income*dwellings, Length: 10830, dtype: float64
group = meshblocks_with_income.groupby("OBJECTID")
df["Census2013_avg_HH_income"] = group["income*dwellings"].sum() / group["2013_Census_total_households_in_occupied_private_dwellings"].sum()
df[["Name", "Census2013_population", "Census2013_dwellings", "Census2013_avg_HH_income"]].sort_values(by="Census2013_population", ascending=False)
| Name | Census2013_population | Census2013_dwellings | Census2013_avg_HH_income | |
|---|---|---|---|---|
| OBJECTID | ||||
| 9 | Henderson-Massey | 107658 | 34461.0 | 68347.842761 |
| 2 | Beach Haven-Birkenhead-Northcote | 82431 | 28344.0 | 80154.552207 |
| 13 | Manurewa | 82230 | 22584.0 | 69202.861326 |
| 17 | Orakei | 79581 | 29001.0 | 110143.425140 |
| 1 | Auckland Central | 77058 | 31506.0 | 86499.398108 |
| 33 | Whau | 72585 | 23928.0 | 65948.529781 |
| 12 | Mangere-Otahuhu | 70998 | 17427.0 | 61855.553636 |
| 4 | Devonport-Takapuna | 55398 | 20307.0 | 89560.517751 |
| 30 | Upper Harbour Local Board Area | 53571 | 17079.0 | 92354.882984 |
| 22 | Puketapapa | 52959 | 16695.0 | 75460.348858 |
| 15 | Mt Albert | 47913 | 15630.0 | 97670.686671 |
| 3 | Botany | 46878 | 13893.0 | 93325.464764 |
| 16 | Mt Eden | 46752 | 16155.0 | 83313.629602 |
| 20 | Papakura | 45687 | 14919.0 | 68043.070707 |
| 21 | Papatoetoe | 45633 | 13272.0 | 65055.631090 |
| 10 | Hibiscus Coast | 45141 | 17397.0 | 70786.765722 |
| 5 | East Coast Bays | 44634 | 15354.0 | 96602.171362 |
| 28 | Tamaki | 42189 | 13551.0 | 64390.277469 |
| 11 | Howick | 40299 | 13836.0 | 85281.267636 |
| 19 | Pakuranga | 39924 | 13206.0 | 82096.046353 |
| 29 | Titirangi | 35958 | 12192.0 | 80713.729357 |
| 7 | Franklin-Pukekohe | 31176 | 10863.0 | 78094.119279 |
| 18 | Otara | 30033 | 6693.0 | 58229.733394 |
| 14 | Maungakiekie | 27780 | 10368.0 | 76915.212333 |
| 6 | Franklin-Beachlands-Hunua | 21111 | 7332.0 | 97416.701031 |
| 24 | Rodney-Helensville | 17832 | 6381.0 | 78202.750119 |
| 26 | Rodney-Warkworth | 17637 | 6912.0 | 62686.367596 |
| 8 | Franklin-Waiuku | 13581 | 5046.0 | 68150.358852 |
| 32 | Waitakere | 12477 | 4449.0 | 84773.121192 |
| 31 | Waiheke | 8310 | 3597.0 | 55066.946309 |
| 25 | Rodney-Kumeu-Riverhead | 7257 | 2472.0 | 86943.048780 |
| 23 | Rodney-Dairy Flat | 6564 | 2130.0 | 106361.971831 |
| 27 | Rodney-Wellsford | 5595 | 2115.0 | 51240.028490 |
df
| Name | geometry | Centroid_lon | Centroid_lat | Area | Residential_area | SH_area | MHS_area | MHU_area | THA_area | ... | FU_area | HGI_area | Business_area | Rural_area | Open_area | Hdist_skytower | Coast_indicator | Census2013_population | Census2013_dwellings | Census2013_avg_HH_income | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OBJECTID | |||||||||||||||||||||
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 1.756345e+06 | 5.919756e+06 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | NaN | NaN | 4.770257e+06 | NaN | 2.505081e+06 | 1067.517983 | True | 77058 | 31506.0 | 86499.398108 |
| 2 | Beach Haven-Birkenhead-Northcote | POLYGON ((1757287.966 5925962.738, 1757211.333... | 1.753625e+06 | 5.926512e+06 | 3.406603e+07 | 1.989760e+07 | 5.073543e+06 | 1.007797e+07 | 3.677952e+06 | 9.609651e+05 | ... | NaN | NaN | 2.554498e+06 | NaN | 6.442079e+06 | 6948.094501 | True | 82431 | 28344.0 | 80154.552207 |
| 3 | Botany | POLYGON ((1770748.846 5912611.168, 1770889.893... | 1.770751e+06 | 5.908123e+06 | 3.978830e+07 | 1.437879e+07 | 4.003298e+05 | 9.023214e+06 | 2.665899e+06 | 1.402369e+06 | ... | NaN | NaN | 6.222613e+06 | 9.837755e+06 | 4.056828e+06 | 18420.075506 | True | 46878 | 13893.0 | 93325.464764 |
| 4 | Devonport-Takapuna | POLYGON ((1755276.581 5932026.336, 1755278.305... | 1.757922e+06 | 5.927072e+06 | 2.111121e+07 | 1.240583e+07 | 2.595033e+06 | 6.760630e+06 | 2.528557e+06 | 5.216074e+05 | ... | NaN | NaN | 1.165067e+06 | NaN | 2.289014e+06 | 6621.239572 | True | 55398 | 20307.0 | 89560.517751 |
| 5 | East Coast Bays | POLYGON ((1756125.006 5940268.048, 1756139.852... | 1.754813e+06 | 5.936807e+06 | 3.038568e+07 | 1.402263e+07 | 2.429714e+06 | 8.490284e+06 | 9.649423e+05 | 2.219014e+05 | ... | NaN | NaN | 3.126271e+05 | 7.860819e+06 | 3.829094e+06 | 16467.095662 | True | 44634 | 15354.0 | 96602.171362 |
| 6 | Franklin-Beachlands-Hunua | MULTIPOLYGON (((1804302.354 5890738.079, 17905... | 1.786911e+06 | 5.898246e+06 | 7.778987e+08 | 7.835879e+06 | 6.069391e+06 | 3.296486e+04 | NaN | 3.034730e+04 | ... | 1.048487e+07 | NaN | 3.582480e+06 | 4.948783e+08 | 8.000078e+07 | 37193.822526 | True | 21111 | 7332.0 | 97416.701031 |
| 7 | Franklin-Pukekohe | POLYGON ((1765085.620 5897344.807, 1765096.229... | 1.765608e+06 | 5.886701e+06 | 2.717220e+08 | 1.622679e+07 | 6.467033e+06 | 5.660850e+06 | 3.079772e+06 | 3.792095e+05 | ... | 2.256611e+07 | NaN | 1.981925e+06 | 2.111716e+08 | 4.301604e+06 | 34851.656145 | True | 31176 | 10863.0 | 78094.119279 |
| 8 | Franklin-Waiuku | POLYGON ((1744829.308 5899882.633, 1744835.760... | 1.747975e+06 | 5.885553e+06 | 2.997611e+08 | 7.599913e+06 | 4.391057e+05 | 2.379868e+06 | 1.111391e+05 | NaN | ... | 1.885628e+05 | NaN | 5.024976e+06 | 2.704684e+08 | 4.015675e+06 | 36121.662648 | True | 13581 | 5046.0 | 68150.358852 |
| 9 | Henderson-Massey | POLYGON ((1745963.138 5923457.510, 1745945.884... | 1.744589e+06 | 5.920165e+06 | 5.321961e+07 | 3.041467e+07 | 5.403257e+06 | 6.196787e+06 | 1.438878e+07 | 4.167398e+06 | ... | 2.356178e+06 | NaN | 5.410361e+06 | 6.572595e+05 | 5.824062e+06 | 12525.129414 | True | 107658 | 34461.0 | 68347.842761 |
| 10 | Hibiscus Coast | MULTIPOLYGON (((1752023.352 5954803.281, 17520... | 1.753822e+06 | 5.946123e+06 | 7.969308e+07 | 2.547122e+07 | 1.531569e+07 | 1.601068e+06 | 1.640568e+06 | 4.426904e+05 | ... | 3.334191e+06 | NaN | 3.122063e+06 | 2.421639e+07 | 1.334561e+07 | 25832.060623 | True | 45141 | 17397.0 | 70786.765722 |
| 11 | Howick | POLYGON ((1771447.460 5916900.636, 1771474.703... | 1.771680e+06 | 5.914250e+06 | 1.461575e+07 | 1.060461e+07 | 3.809348e+06 | 5.160719e+06 | 1.340626e+06 | 2.939136e+05 | ... | NaN | NaN | 3.478985e+05 | 5.208255e+04 | 1.331571e+06 | 15854.353763 | True | 40299 | 13836.0 | 85281.267636 |
| 12 | Mangere-Otahuhu | MULTIPOLYGON (((1766142.746 5910838.845, 17661... | 1.759727e+06 | 5.906676e+06 | 5.250979e+07 | 1.304669e+07 | 1.231326e+06 | 6.294665e+06 | 3.943621e+06 | 1.366092e+06 | ... | 1.146902e+06 | NaN | 8.392959e+06 | 2.711786e+06 | 7.736789e+06 | 14070.305771 | True | 70998 | 17427.0 | 61855.553636 |
| 13 | Manurewa | POLYGON ((1769432.488 5904664.673, 1769471.312... | 1.767778e+06 | 5.901414e+06 | 3.711616e+07 | 1.691256e+07 | 1.083351e+06 | 1.234376e+07 | 2.890852e+06 | 5.945951e+05 | ... | 1.208450e+06 | NaN | 6.011804e+06 | 3.124826e+05 | 6.021889e+06 | 21865.784349 | True | 82230 | 22584.0 | 69202.861326 |
| 14 | Maungakiekie | POLYGON ((1759418.674 5915517.660, 1759596.351... | 1.760340e+06 | 5.913017e+06 | 1.740899e+07 | 5.002987e+06 | 3.103315e+05 | 2.479102e+06 | 1.117549e+06 | 1.096004e+06 | ... | NaN | NaN | 6.424025e+06 | NaN | 2.818621e+06 | 8151.195589 | True | 27780 | 10368.0 | 76915.212333 |
| 15 | Mt Albert | POLYGON ((1756291.061 5918265.104, 1756266.530... | 1.757313e+06 | 5.916439e+06 | 1.385353e+07 | 8.308876e+06 | 3.715019e+06 | 2.058002e+06 | 1.566702e+06 | 9.691525e+05 | ... | NaN | NaN | 1.219666e+06 | NaN | 9.752424e+05 | 4067.283622 | False | 47913 | 15630.0 | 97670.686671 |
| 16 | Mt Eden | POLYGON ((1751910.995 5920299.659, 1751917.632... | 1.753140e+06 | 5.917074e+06 | 1.448821e+07 | 8.270683e+06 | 1.092566e+06 | 2.464966e+06 | 3.332548e+06 | 1.380604e+06 | ... | NaN | NaN | 1.026338e+06 | NaN | 1.709990e+06 | 5244.560531 | True | 46752 | 16155.0 | 83313.629602 |
| 17 | Orakei | POLYGON ((1759833.395 5920429.502, 1759837.143... | 1.763158e+06 | 5.917941e+06 | 3.234712e+07 | 1.873652e+07 | 1.811262e+06 | 1.210010e+07 | 3.663284e+06 | 1.161878e+06 | ... | NaN | NaN | 1.326911e+06 | NaN | 5.326449e+06 | 6567.770945 | True | 79581 | 29001.0 | 110143.425140 |
| 18 | Otara | MULTIPOLYGON (((1765765.640 5909501.655, 17657... | 1.767680e+06 | 5.907486e+06 | 1.213648e+07 | 5.101724e+06 | 1.985154e+04 | 1.887588e+06 | 2.723733e+06 | 4.705511e+05 | ... | NaN | NaN | 2.434656e+06 | NaN | 2.367666e+06 | 16766.406523 | True | 30033 | 6693.0 | 58229.733394 |
| 19 | Pakuranga | POLYGON ((1769523.742 5920466.582, 1769527.337... | 1.768567e+06 | 5.914765e+06 | 1.527965e+07 | 9.096320e+06 | 3.916487e+04 | 7.010512e+06 | 1.552850e+06 | 4.937933e+05 | ... | NaN | NaN | 5.185541e+05 | NaN | 2.768248e+06 | 12812.703793 | True | 39924 | 13206.0 | 82096.046353 |
| 20 | Papakura | POLYGON ((1772188.699 5902202.011, 1772192.566... | 1.772522e+06 | 5.896717e+06 | 4.022528e+07 | 1.808030e+07 | 1.423108e+06 | 1.187048e+07 | 4.001187e+06 | 2.503432e+05 | ... | 6.270214e+06 | NaN | 4.066388e+06 | 2.638487e+06 | 2.646971e+06 | 28340.533206 | True | 45687 | 14919.0 | 68043.070707 |
| 21 | Papatoetoe | POLYGON ((1765105.421 5908611.893, 1765113.661... | 1.764579e+06 | 5.904969e+06 | 2.497254e+07 | 9.380759e+06 | 1.026630e+06 | 6.202250e+06 | 1.652101e+06 | 4.997783e+05 | ... | 6.587091e+05 | NaN | 7.079133e+06 | NaN | 3.473963e+06 | 17234.007915 | True | 45633 | 13272.0 | 65055.631090 |
| 22 | Puketapapa | POLYGON ((1753132.892 5915040.177, 1753141.101... | 1.755129e+06 | 5.913026e+06 | 1.871805e+07 | 1.108573e+07 | 7.062543e+05 | 6.066849e+06 | 2.942080e+06 | 1.360481e+06 | ... | NaN | NaN | 1.061183e+06 | NaN | 3.279811e+06 | 7732.493593 | True | 52959 | 16695.0 | 75460.348858 |
| 23 | Rodney-Dairy Flat | POLYGON ((1746055.938 5948651.765, 1746067.112... | 1.746208e+06 | 5.940237e+06 | 1.132876e+08 | 2.928810e+06 | 4.415845e+05 | 1.082742e+06 | 7.851764e+05 | 1.177736e+05 | ... | 2.571329e+07 | NaN | 2.402994e+05 | 7.596025e+07 | 3.594364e+06 | 22546.984200 | True | 6564 | 2130.0 | 106361.971831 |
| 24 | Rodney-Helensville | MULTIPOLYGON (((1710567.626 5967865.416, 17106... | 1.727410e+06 | 5.943431e+06 | 7.974650e+08 | 5.122441e+06 | 2.915926e+06 | 4.710662e+05 | 8.037448e+04 | NaN | ... | 4.384484e+05 | NaN | 5.046133e+05 | 7.218524e+08 | 2.634552e+07 | 37521.293694 | True | 17832 | 6381.0 | 78202.750119 |
| 25 | Rodney-Kumeu-Riverhead | POLYGON ((1742532.808 5931237.574, 1742490.377... | 1.737278e+06 | 5.928357e+06 | 5.536146e+07 | 4.569329e+06 | 3.637463e+06 | 8.916239e+05 | 4.024164e+04 | NaN | ... | 8.770729e+06 | NaN | 1.003907e+06 | 3.686394e+07 | 8.429452e+05 | 21330.923764 | True | 7257 | 2472.0 | 86943.048780 |
| 26 | Rodney-Warkworth | MULTIPOLYGON (((1761692.564 5984690.018, 17617... | 1.744566e+06 | 5.965485e+06 | 6.684679e+08 | 1.681370e+07 | 5.952212e+06 | 1.799798e+05 | 6.208502e+04 | NaN | ... | 1.266006e+07 | NaN | 1.633665e+06 | 5.541282e+08 | 3.901882e+07 | 46699.922300 | True | 17637 | 6912.0 | 62686.367596 |
| 27 | Rodney-Wellsford | MULTIPOLYGON (((1746318.204 6000215.757, 17464... | 1.738157e+06 | 5.982600e+06 | 6.404974e+08 | 1.680348e+06 | 1.152092e+06 | NaN | NaN | NaN | ... | 1.064854e+06 | NaN | 4.148911e+05 | 5.748374e+08 | 3.130978e+07 | 64927.125388 | True | 5595 | 2115.0 | 51240.028490 |
| 28 | Tamaki | POLYGON ((1765594.677 5917986.938, 1765609.808... | 1.764669e+06 | 5.914441e+06 | 1.896657e+07 | 8.372005e+06 | 1.763932e+04 | 3.137190e+06 | 2.703557e+06 | 2.513619e+06 | ... | NaN | NaN | 5.024667e+06 | NaN | 2.233061e+06 | 9688.801624 | True | 42189 | 13551.0 | 64390.277469 |
| 29 | Titirangi | POLYGON ((1749038.038 5910572.842, 1749034.230... | 1.745133e+06 | 5.910596e+06 | 4.058868e+07 | 1.476243e+07 | 1.672204e+06 | 2.303941e+06 | 1.039881e+06 | 9.614689e+05 | ... | NaN | NaN | 4.333662e+05 | 8.622547e+06 | 1.203022e+07 | 15542.090769 | True | 35958 | 12192.0 | 80713.729357 |
| 30 | Upper Harbour Local Board Area | MULTIPOLYGON (((1743880.554 5928979.708, 17438... | 1.749241e+06 | 5.930422e+06 | 6.973017e+07 | 2.098467e+07 | 4.506156e+06 | 7.750997e+06 | 3.291655e+06 | 3.947975e+05 | ... | 9.573434e+06 | NaN | 6.433695e+06 | 1.217632e+07 | 8.853710e+06 | 12662.494326 | True | 53571 | 17079.0 | 92354.882984 |
| 31 | Waiheke | MULTIPOLYGON (((1793981.864 5931917.843, 17940... | 1.783354e+06 | 5.925355e+06 | 1.547768e+08 | NaN | NaN | NaN | NaN | NaN | ... | NaN | 1.521384e+08 | NaN | NaN | NaN | 26689.652804 | True | 8310 | 3597.0 | 55066.946309 |
| 32 | Waitakere | MULTIPOLYGON (((1743890.310 5905057.188, 17438... | 1.736071e+06 | 5.911661e+06 | 2.651435e+08 | 3.686649e+06 | 4.685951e+05 | 1.370472e+05 | 2.243794e+05 | NaN | ... | 2.606228e+05 | NaN | 5.718099e+04 | 8.375348e+07 | 1.672914e+08 | 22820.718458 | True | 12477 | 4449.0 | 84773.121192 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 1.750066e+06 | 5.914130e+06 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | NaN | NaN | 3.309943e+06 | NaN | 2.842184e+06 | 9497.105591 | True | 72585 | 23928.0 | 65948.529781 |
33 rows × 21 columns
df.to_csv("output/Local_Area.csv")
mb = gpd.read_file("input/statsnzmeshblock-higher-geographies-2018-generalised-FGDB.zip!meshblock-higher-geographies-2018-generalised.gdb")
mb = mb[(mb.TA2018_V1_00_NAME == "Auckland") & mb.LANDWATER_NAME.isin(["Mainland", "Island"])]
mb = mb.rename(columns={"MB2018_V1_00": "Code"})
mb["Centroid_lon"] = mb.centroid.x
mb["Centroid_lat"] = mb.centroid.y
mb
| Code | SA12018_V1_00 | SA22018_V1_00 | SA22018_V1_00_NAME | UR2018_V1_00 | UR2018_V1_00_NAME | IUR2018_V1_00 | IUR2018_V1_00_NAME | CB2018_V1_00 | CB2018_V1_00_NAME | ... | WARD2018_V1_00 | WARD2018_V1_00_NAME | LANDWATER | LANDWATER_NAME | LAND_AREA_SQ_KM | AREA_SQ_KM | Shape_Length | geometry | Centroid_lon | Centroid_lat | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 543 | 0137200 | 7001157 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | ... | 07601 | Rodney Ward | 11 | Island | 0.097567 | 0.097567 | 1356.404986 | MULTIPOLYGON (((1761489.925 5985285.678, 17614... | 1.761464e+06 | 5.985098e+06 |
| 544 | 0170700 | 7001317 | 114300 | Gulf Islands | 1098 | Other rural Auckland | 22 | Rural other | 07602 | Hibiscus and Bays Local Board Area | ... | 07602 | Albany Ward | 11 | Island | 0.005545 | 0.005545 | 321.185380 | MULTIPOLYGON (((1753753.763 5954256.206, 17537... | 1.753808e+06 | 5.954210e+06 |
| 545 | 0438700 | 7001130 | 111800 | Barrier Islands | 1098 | Other rural Auckland | 22 | Rural other | 07608 | Great Barrier Local Board Area | ... | 07605 | Waitemata and Gulf Ward | 11 | Island | 70.725594 | 70.725594 | 100201.649851 | MULTIPOLYGON (((1815954.125 6007877.906, 18159... | 1.814416e+06 | 6.001384e+06 |
| 546 | 0439306 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | ... | 07605 | Waitemata and Gulf Ward | 11 | Island | 0.078233 | 0.078233 | 1494.370224 | MULTIPOLYGON (((1823569.424 5979782.392, 18235... | 1.823537e+06 | 5.979605e+06 |
| 547 | 0439307 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | ... | 07605 | Waitemata and Gulf Ward | 11 | Island | 0.475337 | 0.475337 | 3408.621475 | MULTIPOLYGON (((1824128.365 5979223.530, 18242... | 1.823950e+06 | 5.978887e+06 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 53299 | 4011884 | 7001155 | 110400 | Cape Rodney | 1073 | Whangateau | 21 | Rural settlement | 07601 | Rodney Local Board Area | ... | 07601 | Rodney Ward | 12 | Mainland | 1.161280 | 1.161280 | 7266.530123 | MULTIPOLYGON (((1759217.632 5980700.819, 17596... | 1.758846e+06 | 5.980192e+06 |
| 53301 | 4011883 | 7001154 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | ... | 07601 | Rodney Ward | 12 | Mainland | 7.680889 | 7.680889 | 17076.458542 | MULTIPOLYGON (((1756196.931 5982761.262, 17562... | 1.757339e+06 | 5.980998e+06 |
| 53333 | 4011925 | 7009199 | 156900 | Baverstock | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | ... | 07610 | Howick Ward | 12 | Mainland | 0.242189 | 0.242189 | 2352.598074 | MULTIPOLYGON (((1770681.901 5909197.803, 17711... | 1.771009e+06 | 5.908956e+06 |
| 53359 | 4011971 | 7009313 | 158600 | Ormiston East | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | ... | 07610 | Howick Ward | 12 | Mainland | 0.487587 | 0.487587 | 3692.342983 | MULTIPOLYGON (((1771223.196 5906518.069, 17715... | 1.771828e+06 | 5.906150e+06 |
| 53360 | 4011972 | 7009335 | 158900 | Tuscany Heights | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | ... | 07610 | Howick Ward | 12 | Mainland | 0.178460 | 0.178460 | 1798.203501 | MULTIPOLYGON (((1772642.183 5906246.394, 17726... | 1.772697e+06 | 5.905962e+06 |
13441 rows × 30 columns
mb = mb.set_index("Code")
skytower = Point(1757109.809, 5920500.841)
mb["Hdist_skytower"] = mb.centroid.distance(skytower) # meters
mb
| SA12018_V1_00 | SA22018_V1_00 | SA22018_V1_00_NAME | UR2018_V1_00 | UR2018_V1_00_NAME | IUR2018_V1_00 | IUR2018_V1_00_NAME | CB2018_V1_00 | CB2018_V1_00_NAME | CON2018_V1_00 | ... | WARD2018_V1_00_NAME | LANDWATER | LANDWATER_NAME | LAND_AREA_SQ_KM | AREA_SQ_KM | Shape_Length | geometry | Centroid_lon | Centroid_lat | Hdist_skytower | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Code | |||||||||||||||||||||
| 0137200 | 7001157 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | 0299 | ... | Rodney Ward | 11 | Island | 0.097567 | 0.097567 | 1356.404986 | MULTIPOLYGON (((1761489.925 5985285.678, 17614... | 1.761464e+06 | 5.985098e+06 | 64744.057618 |
| 0170700 | 7001317 | 114300 | Gulf Islands | 1098 | Other rural Auckland | 22 | Rural other | 07602 | Hibiscus and Bays Local Board Area | 0299 | ... | Albany Ward | 11 | Island | 0.005545 | 0.005545 | 321.185380 | MULTIPOLYGON (((1753753.763 5954256.206, 17537... | 1.753808e+06 | 5.954210e+06 | 33870.034882 |
| 0438700 | 7001130 | 111800 | Barrier Islands | 1098 | Other rural Auckland | 22 | Rural other | 07608 | Great Barrier Local Board Area | 0299 | ... | Waitemata and Gulf Ward | 11 | Island | 70.725594 | 70.725594 | 100201.649851 | MULTIPOLYGON (((1815954.125 6007877.906, 18159... | 1.814416e+06 | 6.001384e+06 | 99126.852773 |
| 0439306 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | 0299 | ... | Waitemata and Gulf Ward | 11 | Island | 0.078233 | 0.078233 | 1494.370224 | MULTIPOLYGON (((1823569.424 5979782.392, 18235... | 1.823537e+06 | 5.979605e+06 | 88914.804842 |
| 0439307 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | 0299 | ... | Waitemata and Gulf Ward | 11 | Island | 0.475337 | 0.475337 | 3408.621475 | MULTIPOLYGON (((1824128.365 5979223.530, 18242... | 1.823950e+06 | 5.978887e+06 | 88749.923755 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 4011884 | 7001155 | 110400 | Cape Rodney | 1073 | Whangateau | 21 | Rural settlement | 07601 | Rodney Local Board Area | 0299 | ... | Rodney Ward | 12 | Mainland | 1.161280 | 1.161280 | 7266.530123 | MULTIPOLYGON (((1759217.632 5980700.819, 17596... | 1.758846e+06 | 5.980192e+06 | 59716.438951 |
| 4011883 | 7001154 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | 0299 | ... | Rodney Ward | 12 | Mainland | 7.680889 | 7.680889 | 17076.458542 | MULTIPOLYGON (((1756196.931 5982761.262, 17562... | 1.757339e+06 | 5.980998e+06 | 60497.860816 |
| 4011925 | 7009199 | 156900 | Baverstock | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | Howick Ward | 12 | Mainland | 0.242189 | 0.242189 | 2352.598074 | MULTIPOLYGON (((1770681.901 5909197.803, 17711... | 1.771009e+06 | 5.908956e+06 | 18068.596395 |
| 4011971 | 7009313 | 158600 | Ormiston East | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | Howick Ward | 12 | Mainland | 0.487587 | 0.487587 | 3692.342983 | MULTIPOLYGON (((1771223.196 5906518.069, 17715... | 1.771828e+06 | 5.906150e+06 | 20557.150466 |
| 4011972 | 7009335 | 158900 | Tuscany Heights | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | Howick Ward | 12 | Mainland | 0.178460 | 0.178460 | 1798.203501 | MULTIPOLYGON (((1772642.183 5906246.394, 17726... | 1.772697e+06 | 5.905962e+06 | 21315.702128 |
13441 rows × 30 columns
mb[mb.Hdist_skytower < 5000].plot(column="Hdist_skytower", legend=True)
plt.title("Meshblocks <5KM from the Skytower")
Text(0.5, 1.0, 'Meshblocks <5KM from the Skytower')
coastline = gpd.read_file("input/lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip!nz-coastlines-and-islands-polygons-topo-150k.gdb")
coastline.boundary.plot()
<AxesSubplot:>
coastline = coastline.dissolve().boundary.iloc[0]
%%time
mb["Hdist_coast"] = [point.distance(coastline) for point in tqdm(mb.centroid)]
CPU times: user 1min 22s, sys: 160 ms, total: 1min 22s Wall time: 1min 22s
mb["Hdist_coast"].describe() # meters
count 13441.000000 mean 1596.010824 std 1792.477098 min 0.488582 25% 444.163564 50% 1076.033671 75% 2116.959738 max 16027.664069 Name: Hdist_coast, dtype: float64
mb.plot(column="Hdist_coast", legend=True)
<AxesSubplot:>
OSRM API docs - http://project-osrm.org/docs/v5.24.0/api/#table-service
len(mb)
13441
BASE_URL = "http://osrm.auckland-cer.cloud.edu.au"
def drive(points, to):
points = [f"{point.x},{point.y}" for point in points]
points = ";".join(points)
result = requests.get(f"{BASE_URL}/table/v1/driving/{to};{points}?destinations=0&annotations=duration,distance")
return result.json()
skytower = "174.76218883819053,-36.848429166610735"
%%time
result = drive(points=mb.centroid.to_crs(epsg=4326), to=skytower)
CPU times: user 1.24 s, sys: 57 µs, total: 1.24 s Wall time: 1min 15s
result.keys()
dict_keys(['code', 'sources', 'destinations', 'durations', 'distances'])
mb["Mdist_skytower"] = [r[0] for r in result["distances"][1:]]
mb["Mdist_skytower"].describe() # Units are meters
count 13441.000000 mean 21083.293989 std 15682.240482 min 59.500000 25% 11506.700000 50% 17201.300000 75% 24218.100000 max 136633.200000 Name: Mdist_skytower, dtype: float64
mb.plot(column="Mdist_skytower", legend=True)
<AxesSubplot:>
mb[mb.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
plt.title("Meshblocks <5KM driving from the Skytower")
Text(0.5, 1.0, 'Meshblocks <5KM driving from the Skytower')
# Some strange gaps there - let's investigate
points = mb[(mb.Hdist_skytower < 1000) & (mb.Mdist_skytower > 5000)]
points = [f"{point.x},{point.y}" for point in points.centroid.to_crs(epsg=4326)]
points
['174.75624867471396,-36.85383185528419', '174.75345762242358,-36.850503483712096', '174.75551843174853,-36.8526249602678', '174.75734772557055,-36.855642008978414']
routes = []
for point in points:
route_result = requests.get(f"{BASE_URL}/route/v1/driving/{skytower};{point}?geometries=geojson")
routes.extend(route_result.json()["routes"])
routes
[{'geometry': {'coordinates': [[174.762021, -36.848507],
[174.762081, -36.848111],
[174.761663, -36.847994],
[174.760279, -36.851092],
[174.756401, -36.856918],
[174.756298, -36.858244],
[174.757545, -36.859416],
[174.761092, -36.859842],
[174.763064, -36.860822],
[174.764566, -36.862759],
[174.766927, -36.864565],
[174.768415, -36.867436],
[174.774277, -36.87211],
[174.774115, -36.872578],
[174.773385, -36.872143],
[174.771509, -36.870028],
[174.768209, -36.867454],
[174.766746, -36.864588],
[174.764693, -36.863068],
[174.76298, -36.861326],
[174.761243, -36.860494],
[174.758161, -36.860144],
[174.756868, -36.859449],
[174.755729, -36.85724],
[174.756435, -36.854967],
[174.756232, -36.853838]],
'type': 'LineString'},
'legs': [{'steps': [],
'distance': 6623.4,
'duration': 471.2,
'summary': '',
'weight': 482.5}],
'distance': 6623.4,
'duration': 471.2,
'weight_name': 'routability',
'weight': 482.5},
{'geometry': {'coordinates': [[174.762021, -36.848507],
[174.761973, -36.848406],
[174.762081, -36.848111],
[174.761663, -36.847994],
[174.760403, -36.850878],
[174.75828, -36.854101],
[174.758023, -36.853973],
[174.756934, -36.853677],
[174.756692, -36.853485],
[174.756478, -36.853123],
[174.756232, -36.85299],
[174.755149, -36.853046],
[174.75503, -36.853003],
[174.754968, -36.852487],
[174.754131, -36.851451],
[174.753566, -36.85047]],
'type': 'LineString'},
'legs': [{'steps': [],
'distance': 1487.9,
'duration': 201.1,
'summary': '',
'weight': 212.4}],
'distance': 1487.9,
'duration': 201.1,
'weight_name': 'routability',
'weight': 212.4},
{'geometry': {'coordinates': [[174.762021, -36.848507],
[174.762081, -36.848111],
[174.760362, -36.847639],
[174.756384, -36.84814],
[174.75646, -36.846119],
[174.751793, -36.844936],
[174.749101, -36.843285],
[174.746338, -36.842436],
[174.744751, -36.840654],
[174.742077, -36.838893],
[174.741435, -36.837888],
[174.74165, -36.836424],
[174.749967, -36.823771],
[174.750195, -36.822768],
[174.749701, -36.81919],
[174.751533, -36.813923],
[174.750898, -36.812294],
[174.753046, -36.811822],
[174.753968, -36.812071],
[174.754297, -36.812877],
[174.753791, -36.813549],
[174.75206, -36.814361],
[174.751215, -36.815353],
[174.750131, -36.819403],
[174.750332, -36.822928],
[174.750102, -36.823818],
[174.741981, -36.836162],
[174.74164, -36.837484],
[174.742147, -36.838632],
[174.744931, -36.840513],
[174.746304, -36.842152],
[174.749683, -36.843296],
[174.752518, -36.845063],
[174.752984, -36.845821],
[174.753572, -36.850065],
[174.755481, -36.852645]],
'type': 'LineString'},
'legs': [{'steps': [],
'distance': 11247.2,
'duration': 783.1,
'summary': '',
'weight': 794.4}],
'distance': 11247.2,
'duration': 783.1,
'weight_name': 'routability',
'weight': 794.4},
{'geometry': {'coordinates': [[174.762021, -36.848507],
[174.761973, -36.848406],
[174.762081, -36.848111],
[174.761663, -36.847994],
[174.760403, -36.850878],
[174.758622, -36.85365],
[174.757737, -36.854764],
[174.757261, -36.855607]],
'type': 'LineString'},
'legs': [{'steps': [],
'distance': 1022.2,
'duration': 135,
'summary': '',
'weight': 146.3}],
'distance': 1022.2,
'duration': 135,
'weight_name': 'routability',
'weight': 146.3}]
route_df = pd.read_json(json.dumps(routes))
route_df["geometry"] = route_df['geometry'].apply(shape)
route_df = gpd.GeoDataFrame(route_df)
route_df
| geometry | legs | distance | duration | weight_name | weight | |
|---|---|---|---|---|---|---|
| 0 | LINESTRING (174.76202 -36.84851, 174.76208 -36... | [{'steps': [], 'distance': 6623.4, 'duration':... | 6623.4 | 471.2 | routability | 482.5 |
| 1 | LINESTRING (174.76202 -36.84851, 174.76197 -36... | [{'steps': [], 'distance': 1487.9, 'duration':... | 1487.9 | 201.1 | routability | 212.4 |
| 2 | LINESTRING (174.76202 -36.84851, 174.76208 -36... | [{'steps': [], 'distance': 11247.2, 'duration'... | 11247.2 | 783.1 | routability | 794.4 |
| 3 | LINESTRING (174.76202 -36.84851, 174.76197 -36... | [{'steps': [], 'distance': 1022.2, 'duration':... | 1022.2 | 135.0 | routability | 146.3 |
from shapely.geometry import shape
ax = mb[mb.Mdist_skytower < 5000].to_crs(epsg=4326).plot(column="Mdist_skytower", legend=True)
route_df[route_df["distance"]>10000].plot(column="distance", legend=True, ax=ax, linewidth=3, cmap="plasma")
<AxesSubplot:>
points = mb[(mb.Hdist_skytower < 1000) & (mb.Mdist_skytower > 5000)]
points = [f"{point.y},{point.x}" for point in points.centroid.to_crs(epsg=4326)]
for point in points:
print(f"https://map.project-osrm.org/?loc={point}&loc=-36.848429166610735,174.76218883819053&srv=0")
https://map.project-osrm.org/?loc=-36.85383185528419,174.75624867471396&loc=-36.848429166610735,174.76218883819053&srv=0 https://map.project-osrm.org/?loc=-36.850503483712096,174.75345762242358&loc=-36.848429166610735,174.76218883819053&srv=0 https://map.project-osrm.org/?loc=-36.8526249602678,174.75551843174853&loc=-36.848429166610735,174.76218883819053&srv=0 https://map.project-osrm.org/?loc=-36.855642008978414,174.75734772557055&loc=-36.848429166610735,174.76218883819053&srv=0
mb["Mtime_skytower"] = [r[0] for r in result["durations"][1:]]
mb["Mtime_skytower"].describe() # Units are seconds
count 13441.000000 mean 1594.367316 std 3358.619612 min 15.100000 25% 867.000000 50% 1163.400000 75% 1514.500000 max 70521.800000 Name: Mtime_skytower, dtype: float64
mb[mb.Mtime_skytower < 60*20].plot(column="Mtime_skytower", legend=True)
plt.title("Meshblocks < 20 minutes drive from the Skytower")
Text(0.5, 1.0, 'Meshblocks < 20 minutes drive from the Skytower')
%%time
neg = drive(points=mb.centroid.translate(xoff=-100).to_crs(epsg=4326), to=skytower)
CPU times: user 1.84 s, sys: 0 ns, total: 1.84 s Wall time: 1min 11s
%%time
pos = drive(points=mb.centroid.translate(xoff=100).to_crs(epsg=4326), to=skytower)
CPU times: user 2.18 s, sys: 0 ns, total: 2.18 s Wall time: 1min 18s
mb["Mdist_skytower_center"] = mb["Mdist_skytower"]
mb["Mdist_skytower_west"] = [r[0] for r in neg["distances"][1:]]
mb["Mdist_skytower_east"] = [r[0] for r in pos["distances"][1:]]
mb[["Mdist_skytower_center", "Mdist_skytower_west", "Mdist_skytower_east"]].describe()
| Mdist_skytower_center | Mdist_skytower_west | Mdist_skytower_east | |
|---|---|---|---|
| count | 13441.000000 | 13441.000000 | 13441.000000 |
| mean | 21083.293989 | 21076.932974 | 21080.920289 |
| std | 15682.240482 | 15680.363394 | 15684.086849 |
| min | 59.500000 | 110.700000 | 155.200000 |
| 25% | 11506.700000 | 11485.800000 | 11514.800000 |
| 50% | 17201.300000 | 17202.300000 | 17154.200000 |
| 75% | 24218.100000 | 24203.500000 | 24235.700000 |
| max | 136633.200000 | 136633.200000 | 136633.200000 |
mb["Mdist_skytower"] = mb[["Mdist_skytower", "Mdist_skytower_west", "Mdist_skytower_east"]].min(axis=1)
(mb["Mdist_skytower_center"] - mb["Mdist_skytower"]).describe()
count 13441.000000 mean 200.675322 std 464.749034 min 0.000000 25% 26.300000 50% 92.600000 75% 193.500000 max 12976.900000 dtype: float64
mb[mb.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
plt.title("Meshblocks <5KM driving from the Skytower")
Text(0.5, 1.0, 'Meshblocks <5KM driving from the Skytower')
# Still not quite right - try shift meshblock centroid to nearest parcel centroid
nz_parcels = gpd.read_file('input/lds-nz-primary-parcels-FGDB.zip!nz-primary-parcels.gdb')
print(nz_parcels.crs)
epsg:4167
nz_parcels = nz_parcels.to_crs(mb.crs)
nz_parcels.parcel_intent.value_counts()
DCDB 342691 Fee Simple Title 138388 Road 50033 Hydro 1909 Legalisation 1630 Vesting on Deposit for Local Purpose Reserve 1327 Vesting on Deposit for Recreation Reserve (Territorial Authority) 526 Railway 249 Common Marine and Coastal Area (Sec 237A(1)(b) RM Act) 173 Maori 106 Residue Parcel 74 Vesting on Deposit in the Crown (Sec 237A(1)(b) RM Act) 39 Vesting on Deposit in the Territorial Authority (Sec 237A(1)(a) RM Act) 38 Vesting on Deposit for Recreation Reserve (Crown) 33 Reclamation Area 9 Statutory 9 Vesting on Deposit for Historic Reserve (Territorial Authority) 8 Vesting on Deposit for Scenic Reserve (Territorial Authority) 8 Vesting on Deposit in Lieu of a Reserve (Territorial Authority) 8 Strata 7 Lease 7 Streambed 5 Vesting on Deposit for Scenic Reserve (Crown) 4 Vesting on Deposit in the Crown (Sec 239(1)(c) RM Act) 4 Accretion 2 Vesting on Deposit for Nature Reserve (Crown) 1 UNKN 1 Vesting on Deposit in Lieu of a Reserve (Crown) 1 Name: parcel_intent, dtype: int64
len(nz_parcels)
537290
nz_parcels = nz_parcels[~nz_parcels.parcel_intent.isin(["Hydro", "Road", "Railway"])]
len(nz_parcels)
485099
from scipy.spatial import cKDTree
btree = cKDTree(np.array(list(nz_parcels.centroid.apply(lambda x: (x.x, x.y)))))
%%time
dist, idx = btree.query(np.array(list(mb.centroid.apply(lambda x: (x.x, x.y)))), k=1)
pd.Series(dist).describe()
CPU times: user 558 ms, sys: 54 µs, total: 558 ms Wall time: 557 ms
count 13441.000000 mean 28.794665 std 58.531502 min 0.001892 25% 9.260330 50% 15.164456 75% 23.871677 max 1672.178656 dtype: float64
%%time
shifted_to_nearest_parcel_centroid = drive(points=nz_parcels.centroid.iloc[idx].to_crs(epsg=4326), to=skytower)
CPU times: user 2.6 s, sys: 9.63 ms, total: 2.61 s Wall time: 1min 13s
mb[["Mdist_skytower", "Mdist_skytower_west", "Mdist_skytower_east", "Mdist_skytower_nearest_parcel_centroid"]].describe()
| Mdist_skytower | Mdist_skytower_west | Mdist_skytower_east | Mdist_skytower_nearest_parcel_centroid | |
|---|---|---|---|---|
| count | 13441.000000 | 13441.000000 | 13441.000000 | 13441.000000 |
| mean | 20874.151603 | 21076.932974 | 21080.920289 | 21080.053114 |
| std | 15676.127205 | 15680.363394 | 15684.086849 | 15686.134842 |
| min | 59.500000 | 110.700000 | 155.200000 | 59.500000 |
| 25% | 11290.200000 | 11485.800000 | 11514.800000 | 11506.300000 |
| 50% | 16970.400000 | 17202.300000 | 17154.200000 | 17195.200000 |
| 75% | 24006.200000 | 24203.500000 | 24235.700000 | 24190.000000 |
| max | 136633.200000 | 136633.200000 | 136633.200000 | 136633.200000 |
mb["Mdist_skytower_nearest_parcel_centroid"] = [r[0] for r in shifted_to_nearest_parcel_centroid["distances"][1:]]
ax = mb[mb.Hdist_skytower < 4000].to_crs(epsg=4326).plot(column="Mdist_skytower", legend=True)
mb[mb.Hdist_skytower < 4000].centroid.to_crs(epsg=4326).plot(ax=ax, color="red")
nz_parcels.centroid.iloc[idx[mb.Hdist_skytower < 4000]].to_crs(epsg=4326).plot(ax=ax, color="blue")
<AxesSubplot:>
mb["Mdist_skytower"] = mb[["Mdist_skytower", "Mdist_skytower_west", "Mdist_skytower_east", "Mdist_skytower_nearest_parcel_centroid"]].min(axis=1)
(mb["Mdist_skytower_center"] - mb["Mdist_skytower"]).describe()
count 13441.000000 mean 209.142385 std 480.388408 min 0.000000 25% 31.000000 50% 94.600000 75% 199.000000 max 12976.900000 dtype: float64
mb[mb.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
plt.title("Meshblocks <5KM driving from the Skytower")
Text(0.5, 1.0, 'Meshblocks <5KM driving from the Skytower')
mb.drop(columns="geometry").to_csv("output/2018_Meshblocks.csv")